<template>
	<view>
		<scroll-view scroll-y="true" :refresher-triggered="triggered" class="scroll-y" @refresherrefresh="handleRefresh"
			@scrolltolower="lower" :style="{height:scrollHeight}" :enhanced="true" :show-scrollbar="true">
			<view v-if="showType=='list'">
				<u-sticky>
				<view class="list head  flex-s">
					<view class="list_son">报修时间</view>
					<view class="list_son">故障现象</view>
					<view class="list_son">维修时间</view>
					<view class="list_son">详情</view>
				</view>
				</u-sticky>
				<view class="list flex-s" v-for="(item,index) in list" :key="index">
					<view class="list_son">{{moment(item.created_at).format("YYYY-MM-DD")}}</view>
					<view class="list_son">{{item.describe || '--'}}</view>
					<view class="list_son">{{item.dotime&&moment(item.dotime).format("YYYY-MM-DD") || '--'}}</view>
					<view class="list_son">
						<view class="btn flex-c" @click="setShowType(index)">查看</view>
					</view>
				</view>
			</view>
			<view v-else>


				<view class="card" v-for="(item,index) in list" :key="index">
					<view class="cell">
						<view class="label">维修记录编号：</view>
						<view class="value"> {{item.device_sns}}
							<view class="icon flex-c" :class="[openIndex==index?'open':'']" @click="setOpen(index)">
								<u-icon size="32rpx" name="arrow-up"></u-icon>
							</view>
						</view>
					</view>
					<view class="line"></view>
					<view class="cell">
						<view class="label" >
							状态：<font :class="'re_status_'+item.member_status">{{item.device_status_name}}</font></view>
					</view>
					<view v-if="openIndex==index">
						<app-deviceCard :itemDetail="info" :toUrl="false" :showOp="false"></app-deviceCard>
						<view v-if="item.member_status==3 || item.member_status==2">
							
						
						<view class="cell">
							<view class="label">维修详情：</view>
						</view>
						<view class="textarea">
							{{item.member_describe}}
						</view>
						<view class="line"></view>
						<view class="cell">
							<view class="label">维修图片</view>
						</view>
						<view class="upload">
							<view class="imgs_list flex-c" v-if="item.member_store_imgs_f&&item.member_store_imgs_f.length>0">
								<view class="imgs_son" v-for="(vo,idx) in item.member_store_imgs_f" :key="idx">

									<u-image :src="vo" mode="aspectFill" width="100px" height="100px"
										@click="$func.previewImage(vo,item.member_store_imgs_f)"></u-image>
								</view>
							</view>
						</view>
						</view>
					</view>
					<view class="cell" v-if="item.member_status>1">
						<view class="label">维修时间：</view>
						<view class="value"> {{item.dotime}}</view>
					</view>
					<view class="cell" v-if="openIndex==index && item.member_status>0">
						<view class="label">维修人员：</view>
						<view class="value"> {{item.name_f}}</view>
					</view>
				</view>
			</view>

	<!-- 		<u-divider text="暂无数据" v-if="list.length==0 && finish"></u-divider>
			<u-divider text="暂无更多数据" v-if="list.length>0 && finish"></u-divider> -->
			<u-divider text="加载中" v-if="loading"></u-divider>
			<view style="height: 140rpx;"  v-if="showType=='list'"></view>
		</scroll-view>
		<view class="btns flex-c"  v-if="showType=='list'" @click="setShowType(index)">查看全部</view>
	</view>
</template>

<script>
	import moment from "moment"
	const systemInfo = uni.getSystemInfoSync();
	const safeArea = systemInfo.safeArea;
	export default {
		name: "deviceCard",
		props: {
			info: {
				type: Object,
				default: () => {}
			},

		},
		data() {
			return {
				moment:moment,
				showType: 'list',
				openIndex: -1,
				status: ['正常', '故障停机', '异常可使用', '报废'],
				loading: false,
				triggered: false,
				finish: false,
				total: 0,
				list: [],
				query: {
					page: 1,
					pageSize: 20
				},
			};
		},
		computed: {
			scrollHeight() {
				return 'calc(100vh  - 102rpx)'
			},
			imgCount() {
				return (imgs) => {
					const list = imgs ? imgs.split('|') : []
					return list.length
				}
			},
			imageList() {
				return (imgs) => {
					console.log(imgs)
					const list = imgs ? imgs.split('|') : []
					return list
				}
			}
		},
		created() {
			this.getList()
		},
		methods: {
			setShowType(index) {
				this.openIndex = index
				this.showType = "card"
			},
			setOpen(index) {
				this.openIndex = this.openIndex == index ? -1 : index
			},
			handleRefresh(e) {
				this.triggered = true;
				setTimeout(() => {
					this.query.page = 1
					this.list = []
					this.getList()
				}, 500)
			},
			lower() {
				console.log(this.info)
				if (this.list.length < this.total) {
					this.query.page = this.query.page + 1
					this.getList()
				} else {
					this.finish = true
					this.loading = false
				}
			},
			getList() {
				this.loading = true
				this.$http.post('/data/api.auth.User/maintenanceList', {
					device_id: this.info.id,
				}).then(res => {
					this.list = [...this.list, ...res.data.list]
					this.total = res.data.page.total || 0
					this.loading = false
					this.triggered = false;
					this.finish = true
				}).catch(() => {
					this.loading = false
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.list {
		background-color: #FFFFFF;
		color: #333333;
		padding: 0 20rpx;
		font-size: 28rpx;
		height:88rpx;

		&.head {
			color: #ADADAD;
			border-top: 1px solid #E9E9E9;
			border-bottom: 1px solid #E9E9E9;
			height: 104rpx;
			
		}

		.list_son {
 
			margin: 10rpx auto;
			overflow: hidden; //超出的文本隐藏
			display: -webkit-box;
			-webkit-line-clamp: 1; // 设置从第几行后开始省略
			-webkit-box-orient: vertical;

			&:nth-child(1) {
				width: 30%;
			}

			&:nth-child(2) {
				flex: 1;
			}

			&:nth-child(3) {
				width: 30%;
			}

			&:nth-child(4) {
				width: 15%;
			}
		}
	}

	.card {
		border-radius: 20px;
		background-color: #FFFFFF;
		margin: 20rpx;
		padding: 20rpx 30rpx;
	}

	.textarea {
		background-color: #F5F5F5;
		border-radius: 10rpx;
		padding: 20rpx;
	}

	.line {
		background-color: #E9E9E9;
		height: 1px;
		margin: 15rpx 0;
	}

	.icon {
		transition-duration: 0.3s;
		width: 40rpx;
		height: 40rpx;

		&.open {
			transform: rotate(180deg);
		}
	}

	.imgs_list {
		padding: 5px 0;
		justify-content: flex-start;

		.imgs_son {
			margin: 0 8px 0 0;
			border-radius: 4px;
			overflow: hidden;
		}
	}

	.cell {
		min-height: 60rpx;

		.label {
			color: #333333;
		}

		.value {
			color: #ADADAD;
		}
	}
	.btn {
		width: 94rpx;
		height: 54rpx;
		background: rgba(79,111,246,1);
		border-radius: 10rpx;
		color: #FFFFFF;
	
	}
	.btns {
		position: fixed;
		left: 40rpx;
		right: 40rpx;
		bottom: 50rpx;
		background: rgba(79,111,246,1);
		border-radius: 10rpx;
		color: #FFFFFF;
		height: 92rpx;
	}
</style>